
#pragma once
#pragma unmanaged

#include <windows.h>
#include <vector>
#include "libpng/png.h"
#include "AbstractEncoder.h"


namespace DDesktopServer
{
	class PngEncoder : public AbstractEncoder
	{
	private:
		int					m_img_width;
		int					m_img_height;
		png_structp			m_png_ptr;
		png_infop			m_png_info_ptr;
		std::vector<char>	m_write_buf;
		std::vector<char>	m_header_buf;
		std::vector<char*>	m_input_img_buf;
		int					m_write_pt;

		static void PngEncoder::PNGWrite(png_structp png_ptr, png_bytep data, png_size_t length);
		static void PngEncoder::PNGFlush(png_structp png_ptr);

	public:
		PngEncoder(void);
		virtual ~PngEncoder();

		virtual bool Init(int width, int height);
		virtual const unsigned char* GetHeader(void) const;
		virtual const unsigned char* GetData(void) const;
		virtual int GetHeaderSize(void) const;
		virtual int GetDataSize(void) const;
		virtual bool Encode(char* data, int length);
		virtual bool WriteToFile(const char* file_name) const;
	};
}

#pragma managed
